<!-- <template>
  <div style="width: 600px;height:400px;"/>
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme

export default {
  data() {
    return {
      // 指定图表的配置项和数据
      option: {
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {
          data: ['销量', '库存量']
        },
        xAxis: {
          data: ['个人店铺投诉总量', '个人店铺商品总量', '个人店铺交易总量', '个人店铺本月交易总量']
        },
        yAxis: {},
        toolbox: { // 工具箱
          show: true,
          feature: {
            dataZoom: {
              yAxisIndex: 'none'
            },
            dataView: {readOnly: false},
            magicType: {type: ['bar', 'line']},
            restore: {}
          }
        },
        series: [{
          name: '销量',
          type: 'bar',
          stack: 'vistors',
          barWidth: '60%',
          data: [20, 20, 36, 10, 10, 20],
          markLine: {
            data: [
              {type: 'average', name: '平均值'}
            ]
          }
        },
        {
          name: '库存量',
          type: 'bar',
          stack: 'vistors',
          barWidth: '60%',
          data: [10, 30, 20, 5, 5, 10],
          markLine: {
            data: [
              {type: 'average', name: '平均值'}
            ]
          }
        }]
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption(this.option)
    }
  }
}
</script> -->


<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20" style="height:252px;">
                    <div class="user-info">
                        <img src="../../assets/logo.png" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name">{{name}}</div>
                            <div>{{role}}</div>
                        </div>
                    </div>
                    <div class="user-info-list">
                        登录时间：
                        <span>{{time | formatDate}}</span>
                    </div>
                    <div class="user-info-list">
                        登录地点：
                        <span>石家庄</span>
                    </div>
					<div class="user-info-list">
					    登录的IP：
					    <span>{{IP}}</span>
					</div>
                </el-card>
                <el-card shadow="hover" >
                    <div slot="header" class="clearfix">
                        <span>语言详情</span>
                    </div>
                    <el-progress :percentage="56" color="#42b983"></el-progress>
                    <el-progress :percentage="34" color="#f1e05a"></el-progress>
                    <el-progress :percentage="14"></el-progress>
                    <el-progress :percentage="11" color="#f56c6c"></el-progress>
                </el-card>
            </el-col>
            <el-col :span="16">
                <el-row :gutter="20" class="mgb20">
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-lx-people grid-con-icon">
									<i class=" Iconfont iconuser" style="font-size: 50px;"></i>
								</i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">{{Home.memberCount}}</div>
                                    <div>会员总量</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-2">
                                <i class="el-icon-lx-notice grid-con-icon">
									<i class=" Iconfont iconzengchangshuai" style="font-size: 50px;"></i>
								</i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">{{Home.memberMonthCount}}</div>
                                    <div>会员本月增长量</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-3">
                                <i class="el-icon-lx-goods grid-con-icon">
									<i class=" Iconfont iconshiming" style="font-size: 50px;"></i>
								</i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">{{Home.memberRealCount}}</div>
                                    <div>会员实名量</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>
                <el-card shadow="hover" style="height:403px;">
                    <div slot="header" class="clearfix">
                        <span>待办事项</span>
                        <el-button style="float: right; padding: 3px 0" type="text">添加</el-button>
                    </div>
					<div ref="echarts" class="simpleDemo"></div>
                    <!-- <el-table :show-header="false" :data="todoList" style="width:100%;">
                        <el-table-column width="40">
                            <template slot-scope="scope">
                                <el-checkbox v-model="scope.row.status"></el-checkbox>
                            </template>
                        </el-table-column>
                        <el-table-column>
                            <template slot-scope="scope">
                                <div
                                    class="todo-item"
                                    :class="{'todo-item-del': scope.row.status}"
                                >{{scope.row.title}}</div>
                            </template>
                        </el-table-column>
                        <el-table-column width="60">
                            <template>
                                <i class="el-icon-edit"></i>
                                <i class="el-icon-delete"></i>
                            </template>
                        </el-table-column>
                    </el-table> -->
                </el-card>
            </el-col>
        </el-row>
		 

    </div>
</template>

<script>
import {getHomeStat} from '../../api/api.js'
import {formatDate} from '../../common/js/date.js'
import echarts from 'echarts'

export default {
    name: 'dashboard',
    data() {
        return {
			loading:false,
			Home:{},
            name: 'admin',
			time:new Date(),
			IP:'',
            todoList: [
                {
                    title: '今天要修复100个bug',
                    status: false
                },
                {
                    title: '今天要修复100个bug',
                    status: false
                },
                {
                    title: '今天要修复100个bug',
                    status: true
                },
                {
                    title: '今天要写100行代码加几个bug吧',
                    status: true
                }
            ],
			chart: null,
			option:  {
				title: {
					text: '视频列表'
				},
				tooltip: {},
				legend: {
					data:['销量']
				},
				xAxis: {
					data: ["视频总量","待审核视频量","今日视频量","本月视频量"]
				},
				yAxis: {},
				series: [{
					name: '销量',
					type: 'bar',
					data: [3660, 1560, 556, 260]
				}],
				color: ['#66FF99'],
			}
        };
    },
	filters: {
	      formatDate(time) {
	        var date = new Date(time);
	        return formatDate(date, 'yyyy-MM-dd hh:mm');
	      }
	    },
    computed: {
        role() {
            return this.name === 'admin' ? '超级管理员' : '普通用户';
        }
    },
	mounted() {
		var Token = sessionStorage.getItem('Token');
		var timestamp=new Date().getTime();
		let para = {
			token: Token,
			timestamp: timestamp
		};
		this.loading = true;
		getHomeStat(para).then((res) => {
			var res = res.data;
			if (res.code != 0) {
				this.$message({
					message: res.message,
					type: 'error'
				});
			} else {
				this.Home = res.data;
				this.loading = false;
				this.IP = sessionStorage.getItem('IP');
			}
		});
		this.getPage()
	},
    methods: {
        changeDate() {
            const now = new Date().getTime();
            this.data.forEach((item, index) => {
                const date = new Date(now - (6 - index) * 86400000);
                item.name = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
            });
        },
		getPage() {
			this.chart = echarts.init(this.$refs.echarts);
			// 使用刚指定的配置项和数据显示图表。
			this.chart.setOption(this.option);
		}
    }
};
</script>


<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(100, 213, 114);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 80px;
    height: 80px;
    border-radius: 50%;
	background: #EEEEEE;
	padding: 4px;
}

.user-info-cont {
    padding-left:15px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}
.simpleDemo {
  width: 600px;
  height:300px;
  margin: 0 auto;
}
a {
  color: #00CC66	;
}
.router-link-active {
  text-decoration: none;
}
</style>
